﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Pantry.DataAccess;
using Pantry.Entity;
using System.Data;
using Pantry.Commons;

namespace Pantry.Business
{
    public class DepartmentBus : IDisposable
    {
        private readonly DepartmentDao _departmentDao;

        public DepartmentBus()
        {
            _departmentDao = new DepartmentDao();
        }

        //public List<Department> SelectDepartmentByDirectorateId()
        //{
        //    DataTable tableDepartments = _departmentDao.SelectDepartmentByDirectorateId();
        //    return tableDepartments.ConvertToList<Department>();
        //}

        //public List<Department> GetDepartmentById(int departmentId)
        //{
        //    DataTable tableDepartment = _departmentDao.GetDepartmentById(departmentId);
        //    return tableDepartment.ConvertToList<Department>();
        //}
        public DataTable SelectDepartmentByDirectorateId(int directorateId)
        {
            return _departmentDao.SelectDepartmentByDirectorateId(directorateId);
        }

        public DataTable GetDepartmentById(int departmentId)
        {
            return _departmentDao.GetDepartmentById(departmentId);
        }

        public bool AddDepartment(Department department)
        {
            int result = _departmentDao.AddDepartment(department);
            return (result != 0);
        }

        public bool UpdateDepartment(Department department)
        {
            int result = _departmentDao.UpdateDepartment(department);
            return (result != 0);
        }

        public bool CheckDepartmentNameExists(string departmentName)
        {
            int result = _departmentDao.CheckDepartmentNameExists(departmentName);
            return (result > 0);
        }

        public bool MarkActivated(int departmentId,bool isActivated)
        {
            int result = _departmentDao.MarkActivated(isActivated,departmentId);
            return (result > 0);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                //_departmentDao.Dispose();
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
